home *** CD-ROM | disk | FTP | other *** search
/ Eagles Nest BBS 8 / Eagles_Nest_Mac_Collection_Disc_8.TOAST / Developer Tools⁄Additions / MacUserProj / MacUser Projects / June / 2GenApp Src / AppInit.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-25  |  5.7 KB  |  191 lines  |  [TEXT/KAHL]

  1. /* *****************************************************************************
  2.     FILE:             AppInit.c
  3.     
  4.     DESCRIPTION:     Application Initialization Utilities
  5.  
  6.     AUTHOR:            Kurt W.G. Matthies
  7.         
  8.     Copyright © 1990 by Code of the West, Inc., All Rights Reserved.
  9.  
  10.     
  11.     Revision History:
  12.     ==========================================================
  13.     4.24.90    -    June 1990 MacUser Release (multiple windows)
  14.     3.30.90 -     May 1990 MacUser Release (miniGenApp)
  15.     ==========================================================
  16.  
  17.    ***************************************************************************** */
  18. #include "AppGlobals.h"
  19. #include "MenuConstants.h"
  20.  
  21. #include "AboutBoxPr.h"
  22. #include "DocUtilPr.h"
  23. #include "ShellPr.h"
  24.  
  25. #include "AppInitPr.h"
  26.  
  27. /* -----------------  Local Constants  ---------------------------------- */
  28.  
  29. #define    kMastersNeeded    4            /* for pre-alloc of master pointers */
  30.  
  31. #define    kScreenBorder    4            /* these values in pixels */
  32. #define    kIconSize        32        
  33.  
  34.  
  35. /* ----------------------------  Local Prototypes  ------------------------------- */
  36. Boolean                    initMem         ( void );
  37. short                    initMenus         ( void );
  38.  
  39. /*----------------------------------------------------------------------------------------
  40.     initApp -    initialize the QD environment and the application state
  41.     3.30.90kwgm
  42. ----------------------------------------------------------------------------------------- */
  43. initApplication ()
  44. {
  45.     short         item;
  46.  
  47.     InitGraf(&thePort);    /* initialize the Mac managers */
  48.     InitFonts ();
  49.     InitWindows();
  50.     InitCursor ();    
  51.     InitMenus  ();
  52.     TEInit ();
  53.     InitDialogs (0L);
  54.     
  55.     splashScreen ();        /* put up splash screen */
  56.     
  57.     if (!initMem())            /* initialize application memory */
  58.     {
  59.         StopAlert (kNotEnufMem, 0L);
  60.         ExitToShell ();
  61.     }
  62.     
  63.     initMenus ();            /* init application menus */
  64.     
  65. } /* initApp */
  66.  
  67. /* ----------------------------------------------------------------------------------------
  68.     openAppDocs -    if application is opened from doc, open those documents. Else put new
  69.     3.30.90kwgm        document up. This is a result of double-clicking on a document in the
  70.                     desktop
  71. ------------------------------------------------------------------------------------------ */
  72. void
  73. openAppDocs ()
  74. {
  75.     Boolean        openedOne;
  76.     
  77.     /* GenApp has no documents - this is a hook for future use */
  78.     openedOne = false;
  79.     
  80.     if (!openedOne)
  81.         doNewDoc ();
  82.      
  83. } /* openAppDocs */
  84.  
  85. /* ----------------------------------------------------------------------------------------
  86.     initMem -    initialize application state/global variables
  87.     3.30.90kwgm
  88.     4.24.90kwgm - modified for multiple window environment
  89. ------------------------------------------------------------------------------------------ */
  90. static Boolean
  91. initMem ()
  92. {
  93.     register short     i;
  94.     short             resW, resH, menuBarHeight;
  95.     Size             sz;
  96.     Boolean            resultCode;
  97.     Rect            grayRgnBounds;
  98.     RgnHandle        grayRgnHdl;
  99.  
  100.     MaxApplZone ();            /* maximize available memory */
  101.  
  102.     /* to avoid memory fragmentation, allocate master pointers at bottom of heap */
  103.     for (i = 0 ; i < kMastersNeeded ; i++)
  104.         MoreMasters();
  105.     
  106.     /* get screen dimensions */
  107.     resW = screenBits.bounds.right - screenBits.bounds.left;
  108.     resH = screenBits.bounds.bottom - screenBits.bounds.top;
  109.     menuBarHeight = GetMBarHeight();
  110.     
  111.     /*
  112.         gScreenRect is the size of the main screen, inset by a margin
  113.     */
  114.     SetRect (&gScreenRect, kScreenBorder, menuBarHeight + kScreenBorder, 
  115.         resW - kScreenBorder, resH - kScreenBorder);
  116.         
  117.     /* 
  118.         this default window rect is offset from the screen's edges by the
  119.         size of an icon 
  120.     */
  121.     SetRect (&gWindowRect, kIconSize, menuBarHeight + kIconSize, 
  122.         resW - kIconSize, resH - kIconSize);
  123.     
  124.     /* what are we running on here (System 4.1 or greater) */
  125.     if (resultCode = SysEnvirons (1, &gSysEnv))
  126.     {
  127.         switch (resultCode) {
  128.             case envNotPresent:
  129.             case envBadSel:
  130.             case envSelTooBig:
  131.             default:
  132.                 StopAlert (kUnknownMach, 0L);    /* unknown environment */
  133.                 ExitToShell ();
  134.                 break;
  135.         }
  136.     }
  137.     else
  138.     {
  139.         /* is WaitNextEvent implemented? - from Macintosh Tech Note #158 */
  140.         if (gSysEnv.machineType > envMachUnknown)
  141.             gHasWNE = NGetTrapAddress (0x60, ToolTrap) != NGetTrapAddress (0x9F, ToolTrap);
  142.         else
  143.             gHasWNE = false;        
  144.     }
  145.  
  146.     /* now get entire gray rgn rect (the size of all monitors) */
  147.     grayRgnHdl = GetGrayRgn ();                    /* known as the 'gray region' */
  148.     grayRgnBounds = (*grayRgnHdl)->rgnBBox;        /* the bounding box for the region */
  149.     resW = grayRgnBounds.right - grayRgnBounds.left;
  150.     resH = grayRgnBounds.bottom - grayRgnBounds.top;
  151.     
  152.     /*
  153.         this rect encompasses all of the monitor desktop space,
  154.         minus the menu bar and inset by a margin. We'll use this
  155.         rectangle to limit dragging and resizing windows
  156.     */
  157.     SetRect (&gGrayRgnRect, kScreenBorder, menuBarHeight + kScreenBorder, 
  158.         resW - kScreenBorder, resH - kScreenBorder);
  159.  
  160.     gNumOpenDocs = 0;        /* multiple window globals */
  161.     gNextWindow = 1;
  162.     
  163.     gDevel = true;            /* can be used to turn on debugging features */
  164.     
  165.     return (true);
  166.     
  167. } /* initMem */
  168.  
  169. /* ---------------------------------------------------------------------------------
  170.     initMenus -        set up the application menus
  171.     3.30.90kwgm        all menu templates are in the resource file
  172. -----------------------------------------------------------------------------------*/
  173. initMenus ()
  174. {
  175.     gDeskMenu = GetMenu (kAppleMenuID);
  176.     AddResMenu (gDeskMenu, 'DRVR');            /* add DAs to the apple menu */
  177.     InsertMenu (gDeskMenu, 0);
  178.     
  179.     gFileMenu = GetMenu (kFileMenuID);    /* read template, get handle */
  180.     InsertMenu (gFileMenu, 0);            /* and insert in the app's menu list */
  181.  
  182.     gEditMenu = GetMenu (kEditMenuID);
  183.     InsertMenu (gEditMenu, 0);
  184.     
  185.     DrawMenuBar();
  186.     
  187. } /* initMenus */
  188.  
  189. /* ===========================================  EOF  ========================================
  190.     Copyright © 1990 by Code of the West, Inc. All Rights Reserved.
  191. ============================================================================================ */